<script src="<?= base_url()?>public/js/jquery.min.js"></script>
<div class="content-wrapper">
    <!-- 内容标题 -->
    <section class="content-header">
      <h1>
        <small>部门管理/</small> 新增部门
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>系统设置</a></li>
        <li><a href="#">部门管理</a></li>
        <li class="active">新增部门</li>
      </ol>
    </section>

    <!-- 内容区 -->
    <form action="<?=base_url()?>index.php/admin/group/store" method="post" id='CreateForm'>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
              <div class="box">
                <div class="box-header with-border">
                   <h3 class="box-title">基础信息</h3>
                </div>
                <div class="box-body detail-page-sy"><br>
                    <dl class="dl-horizontal">
                      <dt>部门名：</dt>
                      <dd>
                        <div class="col-xs-4 row">
                          <input type="text" name="group[name]" fld='name'
                            style='width:245px;' class="form-control"
                            value="<?php echo (isset($name)?$name:'') ?>">
                        </div>
                        <div style='color:red;'></div>
                      </dd><br>
                      <dt>描述：</dt>
                      <dd>
                         <div class="col-xs-4 row">
                            <input type="text" name="group[description]" fld='description'
                            style='width:245px;' class="form-control"
                            value="<?php echo (isset($description)?$description:'') ?>">
                        </div>
                        <div style='color:red;'></div>
                      </dd>
                    </dl>
                </div>
                <!-- /.box-body -->
                <div class="box-footer align-center">
                    <button type="button" class="btn btn-primary btn-big bg-pink" id='submitBtn'>新增</button>
                    <button type="button" class="btn btn-default btn-big" id='cancelBtn'>返回</button>
                </div>
              </div>
            </div>
            <!-- /.col -->
          </div>
    </section>
    </form>
</div>
<script>
$(function(){
    var is_submit = 1;
    $('#submitBtn').on('click',function(){
        var idx = 1;
        $('#CreateForm input[fld=name]').val($.trim($('#CreateForm input[fld=name]').val()));
        if($('#CreateForm input[fld=name]').val() == ''){
            $('#CreateForm input[fld=name]').parent().next().html('请输入部门名称。');
            idx = 0;
        }else{
            $('#CreateForm input[fld=name]').parent().next().html('');
        }
        if(0 == idx){
            return false;
        }
        if(1 != is_submit){
            return false;
        }
        is_submit = 2;
        $('#CreateForm').submit();
    });
    $('#cancelBtn').on('click',function(){
        location.href = '<?=base_url()?>index.php/admin/group/index';
    });
    var error_code = "<?= (isset($error_code)?$error_code:'')?>";
    if(error_code != ''){
        $('#CreateForm input[fld=name]').parent().next().html(error_code);
    }
});
</script>
